﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace LandAppraisal.Controllers
{
    public class DepartmentController : ApiController
    {
        BLL.AdminBLL adminbll = new BLL.AdminBLL();

        #region 获取部门信息表（权限）
        /// <summary>
        /// 获取部门信息表（权限）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Get(string name)
        {
            //return adminbll.GetList<SysDepartment>();
            List<SysDepartment> list;
            if (name == null || name == "")
            {
                list = adminbll.GetList<SysDepartment>().ToList();
            }
            else
            {
                list = adminbll.GetList<SysDepartment>().Where(t => t.Department_Name.Contains(name)).ToList();
            }
            return JsonConvert.SerializeObject(list);
        }
        #endregion

        #region 获取部门信息表
        /// <summary>
        /// 获取部门信息表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string Get()
        {
            return JsonConvert.SerializeObject(adminbll.GetList<SysDepartment>());
        }
        #endregion

        #region 添加部门信息
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="value"></param>
        [HttpPost]
        public int Post([FromBody]SysDepartment dept)
        {
            return adminbll.Add<SysDepartment>(dept);
        }
        #endregion

        #region 修改部门信息
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        [HttpPut]
        public bool Put([FromBody] SysDepartment dept)
        {
            return adminbll.Update<SysDepartment>(dept);
        }
        #endregion

        #region 删除部门信息
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool Delete(int id)
        {
            return adminbll.DeleteById<SysDepartment>(id);
        }
        #endregion

        #region 修改状态
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int UpdateState(int id, int state)
        {
            return adminbll.UpdateState(id, state);
        }
        #endregion

    }
}
